package cn.edu.lingnan.translation.controller;


import cn.edu.lingnan.translation.entity.AdminRole;
import cn.edu.lingnan.translation.entity.RoleMenu;
import cn.edu.lingnan.translation.service.RoleMenuService;
import cn.edu.lingnan.translation.utils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Bao
 * @since 2020-10-21
 */
@RestController
@RequestMapping("/role-menu")
public class RoleMenuController {
    @Autowired
    private RoleMenuService roleMenuService;

    /**
     * @Description 获取角色权限信息
     * @Param []
     * @Return cn.edu.lingnan.translation.utils.R
     * @Author BAO
     * @Date 2020/10/21 17:31
     */
    @ApiOperation(value = "获取角色权限信息")
    @GetMapping("/getRoleMenu")
    public R getRoleMenu() {
        List<RoleMenu> roleMenuList = roleMenuService.list(null);
        return R.ok().data("roleMenuList", roleMenuList);
    }

    /**
     * @Description 为角色添加权限
     * @Param [roleMenu]
     * @Return cn.edu.lingnan.translation.utils.R
     * @Author BAO
     * @Date 2020/10/21 17:29
     */
    @ApiOperation(value = "为角色添加权限")
    @PostMapping("/add")
    public R addAdminRole(@RequestBody RoleMenu roleMenu) {
        roleMenuService.save(roleMenu);
        return R.ok();
    }

    /**
     * @Description 删除该角色的权限
     * @Param [id]
     * @Return cn.edu.lingnan.translation.utils.R
     * @Author BAO
     * @Date 2020/10/21 17:30
     */
    @ApiOperation(value = "删除该角色的权限")
    @DeleteMapping("/{id}")
    public R deleteAdminRole(@PathVariable String id) {
        roleMenuService.removeById(id);
        return R.ok();
    }
}

